import * as vscode from 'vscode';
import * as path from 'path';
import * as os from 'os';

import { buildAPP } from './buildCommands/buildAPP';
import { buildHAP } from './buildCommands/buildHAP';
import { openHarmonyOSEmulator } from './emulator/openHarmonyOSEmulator';
import { DebugSign } from './sign/DebugSign';
export function activate(context: vscode.ExtensionContext) {
    console.log('Congratulations, your extension "harmonyosvsbuild" is now active!');
	let toolsPath: string = vscode.workspace.getConfiguration().get('harmonyosvsbuild.toolsPath') || 'D:\\huawei\\Tools';
	let java17Path: string = vscode.workspace.getConfiguration().get('harmonyosvsbuild.java17Path') || 'D:\\Program Files\\Huawei\\DevEco Studio\\jbr\\bin';
	let HarmonyOSEmulatorsPath: string = vscode.workspace.getConfiguration().get('harmonyosvsbuild.HarmonyOSEmulatorPath') || 'D:\\huawei\\HarmonyOSEmulator';
	let DevEcoPath: string = vscode.workspace.getConfiguration().get('harmonyosvsbuild.DevEcoPath') || 'D:\\Program Files\\Huawei\\DevEco Studio';
	let userDirectory = os.homedir()||'';
	if (!toolsPath) {
        vscode.window.showInformationMessage('Please configure the tools path.');
        return;
    }
	if (!java17Path) {
        vscode.window.showInformationMessage('Please configure the java17 path.');
        return;
    }
	let nodePath  = path.join(toolsPath, 'nodejs');
	let HarmonyOSEmulator  = path.join(toolsPath, 'sdk','hmscore','emulator',"emulator.exe");

	process.env.PATH += path.delimiter + java17Path
					 +	path.delimiter + nodePath;
					
	process.env.HarmonyOS_HVD_HOME = HarmonyOSEmulatorsPath;
	
    let createProjectDisposable = vscode.commands.registerCommand('harmonyosvsbuild.createProject', () => {
        // Implement your command here
        vscode.window.showInformationMessage('Create Project command executed!');
    });

    let buildHAPDisposable = vscode.commands.registerCommand('harmonyosvsbuild.buildHAP', buildHAP);

    let buildAPPDisposable = vscode.commands.registerCommand('harmonyosvsbuild.buildAPP', buildAPP);

    let signProjectDisposable = vscode.commands.registerCommand('harmonyosvsbuild.signProject', () => {
        // Implement your command here
        vscode.window.showInformationMessage('Sign Project command executed!');
    });

    let debugProjectDisposable = vscode.commands.registerCommand('harmonyosvsbuild.debugProject', () => {
        // Implement your command here
        vscode.window.showInformationMessage('Debug Project command executed!');
    });

    let settingDisposable = vscode.commands.registerCommand('harmonyosvsbuild.setting', () => {
        // Implement your command here
        vscode.window.showInformationMessage('Setting command executed!');
    });
	let openHarmonyOSEmulatorDisposable = vscode.commands.registerCommand('harmonyosvsbuild.openHarmonyOSEmulator', () => {
		openHarmonyOSEmulator(HarmonyOSEmulatorsPath,HarmonyOSEmulator);
	});

	let signDebugProjectDisposable = vscode.commands.registerCommand('harmonyosvsbuild.signDebugProject', () => {
		DebugSign(context, DevEcoPath);
	});
    context.subscriptions.push(createProjectDisposable, buildAPPDisposable,buildHAPDisposable, signProjectDisposable, debugProjectDisposable, settingDisposable,openHarmonyOSEmulatorDisposable,signDebugProjectDisposable);
}

export function deactivate() {}